/*******************************************************************************
 ** Name: weapon.cpp                                                          **
 ** Description:                                                              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved 2-clause BSD License                **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry "Gian" James  <bjames@munixos.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  Redistribution and use in source and binary forms, with or without       **
 **  modification, are permitted provided that the following conditions are   **
 **  met:                                                                     **
 **                                                                           **
 **  * Redistributions of source code must retain the above copyright notice, **
 **    this list of conditions and the following disclaimer.                  **
 **  * Redistributions in binary form must reproduce the above copyright      **
 **    notice, this list of conditions and the following disclaimer in the    **
 **    documentation and/or other materials provided with the distribution.   **
 **                                                                           **
 **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      **
 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED **
 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           **
 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT        **
 ** HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    **
 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  **
 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    **
 ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    **
 ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      **
 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        **
 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              **
 **                                                                           **
 ******************************************************************************/
// Modified $Date: 2011-09-18 21:48:59 +0000 (Sun, 18 Sep 2011) $ by $Author: gian.james $
#define _weapon_cpp_ID    "$Id: weapon.cpp 145 2011-09-18 21:48:59Z gian.james $"

#include "weapon.hpp"

static const char *  ammoType[] =
{
    "Full-metal Jacket", "Jacketed Hollowpoint", "Armor Piercing",
    "High Explosive Incendiary", "Flechette", "Less-Than-Lethal",
    "00 Buckshot", "Concussion", "Blank", "Smoke", "Flare",
    "Incendiary", "CS Gas", "Sabot Slug", "Frangible",
    "FMJ", "JHP", "AP", "HEI", "FLE", "LTL", "BUCK", "CONC",
    "BLANK", "SMOKE", "FLARE", "INC", "CS", "SABO", "FRAN"
};

static const char *  dmgType[] =
{
    "Ballistic", "Piercing", "Slashing", "Bludgeoning"
};
static const char *  wpnClass[] = { "Melee", "Ranged" };
static const char *  wpnType[] =
{
    "Improvised", "Axe", "Mace", "Sword", "Spear", "Nunchuku",
    "Knife", "Knuckles", "Club", "Exotic Melee",
    "Handgun", "Assault Rifle", "Bolt-action Rifle", "Sniper Rifle",
    "Shotgun", "Submachine gun", "Machine gun", "Explosives",
    "Hurled", "ExoticRanged"
};

static const char *  wpnFireRate[] = { "Safety", "Single", "Burst", "Auto" };


//////////////////////////[ RangedWeapon
RangedWeapon::RangedWeapon(std::string n)
    : Weapon(n)
{
    recoil      = 0;
    rate        = WpnFireRate::Single;
    selector    = WpnFireRate::Safety;
    wclass      = WpnClass::Ranged;
}

RangedWeapon::RangedWeapon(std::string n, WpnType t, WpnHands h,WpnFireRate fr)
    : Weapon(n,t,h,WpnClass::Ranged,WpnDamage::Ballistic,OType::RangedWeapon)
{
    recoil = 0;
    rate = fr;
    selector = WpnFireRate::Safety;
}

void
RangedWeapon::SetFireRate(WpnFireRate fr)
{
//   if (BCHK((uint8_t)rate,(uint8_t)fr))
        selector = fr;
}

std::string
RangedWeapon::FireRate(WpnFireRate fr)
{
    return wpnFireRate[(uint8_t)fr];
}

int
RangedWeapon::Actionable(std::string cmd, Client * player)
{

}

//////////////////////////[ MeleeWeapon
MeleeWeapon::MeleeWeapon(std::string n,WpnType t,WpnHands h,WpnDamage wd,int s,int d)
    : Weapon(n,t,h,WpnClass::Melee,wd,OType::MeleeWeapon)
{
    minStr = s;
    minDex = d;
}

MeleeWeapon::MeleeWeapon(std::string n)
    : Weapon(n)
{
    minStr = 0;
    minDex = 0;
    wclass = WpnClass::Melee;
}


//////////////////////////[ Ammo

const char *
Ammo::Type(AmmoType at)
{
    return ammoType[(uint8_t)at];
}

const char *
Ammo::TypeAbbr(AmmoType at)
{
    return ammoType[(uint8_t)at+((uint8_t)AmmoType::max)-1];
}

Ammo::Ammo(AmmoType at,char m,int r)
{
    type = at; container = m; rounds = r; 
}


//////////////////////////[ Weapon

void
Weapon::AddTrait(Trait * t)
{
    t->next = traits;
    traits = t;
}

std::string
Weapon::FQType()
{
   std::string     str;
   str = TypeToStr();
   str += ":";
   str += WpnClassToStr(wclass);
   str += ":";
   str += SubTypeToStr(wtype);
   return str;
}

std::string
Weapon::WpnClassToStr(WpnClass wc)
{
    return wpnClass[(uint8_t)wc];
}

std::string
Weapon::SubTypeToStr(WpnType wt)
{
    return wpnType[(uint8_t)wt];
}

std::string
Weapon::DamageType(WpnDamage dt)
{
    return dmgType[(uint8_t)dt];
}

Weapon::Weapon(std::string n,WpnType wt,WpnHands wh,WpnClass wc,WpnDamage wd, OType t)
        : WorldObject(t,n)
{
    wtype = wt; hands = wh; wclass = wc; wdmg = wd;
    range = 0; cost = 0; traits = NULL; dmg.rolls=1; dmg.num=6;
}


Weapon::Weapon(std::string n)
    : WorldObject(OType::Weapon,n)
{
    wtype = WpnType::max;
    hands = WpnHands::One;
    wclass = WpnClass::Ranged;
    wdmg = WpnDamage::Ballistic;
    range = 0; cost = 0; traits = NULL; dmg.rolls=1; dmg.num=0;
}

Weapon::Weapon(const Weapon& orig)
{
}

Weapon::~Weapon()
{
}

